﻿using System;
using System.Reflection;
using System.Linq;
namespace XC.DataAccess.EncoderDecoder
{
    /// <summary>
    /// BCD转换器
    /// </summary>
    public class BcdConverter : IEncoderConverter
    {
        public byte[] Encode<T>(T data, PropertyInfo[] propertyInfos, object source, EncoderAttribute encoderAttribute)
        {
            if (data is string text)
            {
               var number=  Convert.ToUInt64(text);
               var bytes= BitConverter.GetBytes(number);
                return bytes.Take(6).ToArray();
            }
            else
            {
                throw new TypeNotMatchException(typeof(string), data.GetType());
            }
        }
    }
}
